package com.sping_boot3.spirng_boot3.juc.异步回调;

import lombok.SneakyThrows;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class 获取结果和触发计算 {
    @SneakyThrows
    public static void main(String[] args) {
        CompletableFuture<Integer> integerCompletableFuture = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return 1;
        });
//        System.out.println(integerCompletableFuture.get());
//        System.out.println(integerCompletableFuture.get(1L, TimeUnit.SECONDS));
//        System.out.println(integerCompletableFuture.join());
        System.out.println(integerCompletableFuture.getNow(3));
        System.out.println(integerCompletableFuture.complete(3+ integerCompletableFuture.join()));

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
